package dimension.stock;

import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;

import java.math.RoundingMode;

public class StockExpansion extends PlaceholderExpansion {

    @Override
    public boolean persist() {
        return true;
    }

    @Override
    public boolean canRegister() {
        return true;
    }

    @Override
    public String getIdentifier() {
        return MainClass.INSTANCE.getDescription().getName();
    }

    @Override
    public String getAuthor() {
        return MainClass.INSTANCE.getDescription().getAuthors().toString();
    }

    @Override
    public String getVersion() {
        return MainClass.INSTANCE.getDescription().getVersion();
    }

    @Override
    public String onPlaceholderRequest(Player player, String identifier) {
        if ("latestPrice".equals(identifier)) {
            return Config.getLatestPrice().setScale(2, RoundingMode.HALF_UP).toString();
        } else if ("lastDayPrice".equals(identifier)) {
            return Config.getLastDayPrice().setScale(2,RoundingMode.HALF_UP).toString();
        } else if ("stockName".equals(identifier)) {
            return Config.getStockName();
        } else if ("lastDayVolume".equals(identifier)) {
            return Config.getLastDayVolume().toString();
        } else if ("todayVolume".equals(identifier)) {
            return Config.getTodayVolume().toString();
        }
        return null;
    }
}
